package com.boyi.cycling_master.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.boyi.cycling_master.R;
import com.boyi.cycling_master.bean.ResponseBean;
import com.boyi.cycling_master.common.PostParams;
import com.boyi.cycling_master.common.SnackUtil;
import com.boyi.cycling_master.https.utils.UserInfoRetrofit;
import com.boyi.cycling_master.ui.base.BaseActivity;
import com.rengwuxian.materialedittext.MaterialEditText;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 *
 * @date 2017/8/11/011 10:50
 *
 * @author Lee_Mofeel
 *
 * @version 1.0
 *
 * @Description 修改绑定手机逻辑2
 *              验证旧的手机号码
 *
 */

public class PhoneChangeOldActivity extends BaseActivity {


    @BindView(R.id.btn_nav_icon)
    ImageView btnNavIcon;
    @BindView(R.id.edt_change_phone_old)
    MaterialEditText edtChangePhoneOld;
    @BindView(R.id.edt_update_password_new)
    MaterialEditText edtUpdatePasswordNew;
    @BindView(R.id.tv_change_phone_next)
    TextView tvChangePhoneNext;

    @Override
    public int getContentViewId() {
        return R.layout.activity_change_phone_old;
    }

    @Override
    public void initLogic() {

    }

    @Override
    public void getBundleExtras(Bundle bundle) {

    }



    @OnClick({R.id.btn_nav_icon, R.id.tv_change_phone_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_nav_icon:
                finish();
                break;
            case R.id.tv_change_phone_next:
                String phone = edtChangePhoneOld.getText().toString();
                String password = edtUpdatePasswordNew.getText().toString();
                if(TextUtils.isEmpty(password) || TextUtils.isEmpty(password)){
                    SnackUtil.SnackShort(edtChangePhoneOld,"请输入相关信息");
                }else{
                    Map<String,String> map = new HashMap<>();
                    map.put("userPhone",phone);
                    map.put("userPassword",password);
                    /* 提交验证手机号信息到服务器 */
                    UserInfoRetrofit.getInstance().checkedPhone(new Callback<ResponseBean>() {
                        @Override
                        public void onResponse(Call<ResponseBean> call, Response<ResponseBean> response) {
                            if(response.body() == null)
                                return;
                            SnackUtil.SnackShort(edtChangePhoneOld,response.body().getResultMessage());
                            if(response.body().getResultCode().equals("200")){// 验证成功进入到提交新手机界面
                                startActivity(new Intent(PhoneChangeOldActivity.this,PhoneChangeNewActivity.class));
                            }
                        }

                        @Override
                        public void onFailure(Call<ResponseBean> call, Throwable t) {

                        }
                    }, PostParams.makeRequestBody(map));
                }

                break;
        }
    }
}
